<!--
 * @Author: wwssaabb
 * @Date: 2021-08-16 18:05:52
 * @LastEditTime: 2021-08-17 08:36:00
 * @FilePath: \axios_demo\base\base_demo.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
  <title>Document</title>
</head>

<body>
  <div class="container">
    <h2 class="page-header">基本使用</h2>
    <button class="btn btn-primary">发送GET请求</button>
    <button class="btn btn-warning">发送POST请求</button>
    <button class="btn btn-success">发送PUT请求</button>
    <button class="btn btn-danger">发送DELETE请求</button>
  </div>

  <script>
    let buts=document.querySelectorAll('button')
    //基础用法
    // buts[0].onclick=()=>axios({method:'GET',url:'http://localhost:3000/posts'}).then(res=>console.log(res))
    // buts[1].onclick=()=>axios({method:'POST',url:'http://localhost:3000/posts',data:{title:'testestestestestest',author:'test'}}).then(res=>console.log(res))
    // buts[2].onclick=()=>axios({method:'PUT',url:'http://localhost:3000/posts/1',data:{title:'别光喝酒吃点头孢',author:'张三'}}).then(res=>console.log(res))
    // buts[3].onclick=()=>axios({method:'DELETE',url:'http://localhost:3000/posts/7'}).then(res=>console.log(res))
    
    //使用方法
    buts[0].onclick=()=>axios.get('http://localhost:3000/posts').then(res=>console.log(res))
    buts[1].onclick=()=>axios.post('http://localhost:3000/posts',{title:'testestestestestest',author:'test'}).then(res=>console.log(res))
    buts[2].onclick=()=>axios.put('http://localhost:3000/posts/7',{title:'ababababababa',author:'张三'}).then(res=>console.log(res))
    buts[3].onclick=()=>axios.delete('http://localhost:3000/posts/7').then(res=>console.log(res))

    
  </script>
</body>

</html>